<?php

namespace App\Http\Requests\Strator;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateStratorDepartmentRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'id'=>'required|integer|min:0',
            'pid'=>'required|integer|min:0',
            'department_name'=>[
                'required',
                'string',
                'min:1',
                'max:30',
                Rule::unique('strator_departments','department_name')->ignore($this->id??0),
            ],
            'department_code'=>[
                'sometimes',
                'alpha_num',
                'max:20',
                Rule::unique('strator_departments','department_code')->ignore($this->id??0),
            ],
            'department_remark'=>'sometimes|string|max:200',
            'sort'=>'required|integer',

        ];
    }
    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'id.required'=>'id参数为必传',
            'id.integer'=>'id参数错误',
            'id.min'=>'id参数错误',

            'pid.required' => 'pid参数为必传',
            'pid.integer' => 'pid参数不正确',
            'pid.min' => 'pid参数不正确',

            'department_name.required' => '部门名称为必填',
            'department_name.string' => '部门名称只能是字符串类型',
            'department_name.min' => '部门名称长度要在1-30位之间',
            'department_name.max' => '部门名称长度要在1-30位之间',
            'department_name.unique' => '部门名称已存在',

            'department_code.alpha_num' => '部门代码只能是字母或者数字',
            'department_code.max' => '部门代码长度要在1-20位之间',
            'department_code.unique' => '部门代码已存在',

            'department_remark.string' => '部门简介只能是字符串类型',
            'department_remark.max' => '部门简介长度要在1-200个字符之间',

            'sort.integer' => '排序值只能是整数',

        ];
    }
}
